package com.ms.oschina.base;

import android.support.v4.view.ViewPager;
import android.view.View;

import com.ms.oschina.R;
import com.ms.oschina.adapter.ViewPagerFragmentAdapter;
import com.ms.oschina.util.LogUtils;
import com.ms.oschina.view.PagerSlidingTabStrip;

/**
 * 一个含有viewPager和指示器的fragment
 * 
 * @author Administrator
 */
public abstract class BasePagerSlidingTabFragment extends BaseFragment {
	private ViewPager pagerContent;
	private PagerSlidingTabStrip pstGroupTabs;

	private void findViews(View view) {
		pstGroupTabs = (PagerSlidingTabStrip) view
				.findViewById(R.id.pst_group_tabs);
		pagerContent = (ViewPager) view.findViewById(R.id.pager_content);
	}

	@Override
	public int getLayoutId() {
		return R.layout.viewpager_tagpage;
	}

	@Override
	public void initView(View view) {
		findViews(view);
	}

	@Override
	public void initData() {
		pagerContent.setOffscreenPageLimit(offscreenPageLimit());
		ViewPagerFragmentAdapter adapter = new ViewPagerFragmentAdapter(
				getChildFragmentManager(), pagerContent, pstGroupTabs);
		addTab(adapter);
	}

	public int offscreenPageLimit() {
		return 1;
	}

	/**
	 * 添加标题
	 * 
	 * @see adapter.addtab()
	 * @param adapter
	 */
	public abstract void addTab(ViewPagerFragmentAdapter adapter);

}
